//
//  ViewController.m
//  15-Homework
//
//  Created by GivenBmli on 16/8/3.
//  Copyright © 2016年 GivenBmli. All rights reserved.
//

#import "ViewController.h"
#import "BM-CollectionViewCell.h"
#import "BM-CollectionViewLayout.h"
#import "SelfSizeTool.h"
@interface ViewController ()<UICollectionViewDelegate, UICollectionViewDataSource,BM_LayoudDelget>
@property (nonatomic, strong) UICollectionView *coll;
@property (nonatomic, strong) NSMutableArray *dataArr;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    self.navigationController.navigationBar.translucent = NO;
     BM_CollectionViewLayout*lay = [BM_CollectionViewLayout new];
//    scolleiView自动边距
//    遇到状态栏,导航栏,自动为页面上的某一个scrollView添加边距
//    一般在开发中,关闭这个属性
    self.automaticallyAdjustsScrollViewInsets =NO;
//    整个边距往下一
    self.edgesForExtendedLayout = UIRectEdgeNone;
    self.coll = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, 414, 44) collectionViewLayout:lay];
    lay.delegate = self;
    lay.collectionView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:_coll];
    
    _coll.delegate = self;
    _coll.dataSource = self;
    
    [_coll registerNib:[UINib nibWithNibName:@"BM-CollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"1"];
    _dataArr = [NSMutableArray arrayWithObjects:@"头条", @"精选", @"娱乐", @"体育", @"网易号", @"本地", @"视频", @"财经", @"科技", @"汽车", @"时尚", @"图片", @"直播", @"热点", @"跟贴", nil];
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout widthForItemAtIndexPath:(NSIndexPath *)indexPath height:(CGFloat)height {


    return [SelfSizeTool selfSizeHeightWithString:_dataArr[indexPath.row] height:height font:[UIFont systemFontOfSize:17]];
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return _dataArr.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    BM_CollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"1" forIndexPath:indexPath];
    cell.backgroundColor = [UIColor greenColor];
    cell.label.text = _dataArr[indexPath.row];
    return cell;
}






- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
